/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package cs575.wido.action;

import cs575.client.GroupEx;
import cs575.client.Session;
import cs575.client.WiDo;
import cs575.wido.UserSession;
import cs575.wido.WebServiceFactory;
import cs575.wido.ui.TaskDetailsWindow;
import cs575.wido.ui.TaskWindow;
import java.awt.event.ActionEvent;
import javax.swing.AbstractAction;
import javax.swing.JOptionPane;

/**
 *
 * @author kevincheung
 */
public class AddTaskAction extends AbstractAction {
	private TaskDetailsWindow parent;
        private TaskWindow window;
	public AddTaskAction(TaskDetailsWindow parent, TaskWindow window) {
		putValue(NAME, "OK");
		this.parent = parent;
                this.window = window;
	}

	@Override
	public void actionPerformed(ActionEvent ae) {
		WiDo wido = WebServiceFactory.getPort();
		UserSession userSession = UserSession.getInstance();
		Session session = userSession.getSession();
		
		String name = parent.getName();
		String description = parent.getDescription();
		String due_date = parent.getDueDate();
		
		cs575.client.Task t = wido.createPrivateTask(session, name, description, due_date);
		if(t != null) {
			JOptionPane.showMessageDialog(null, "Taskname "+t.getTaskName());
			parent.dispose();
		}
		else {
			JOptionPane.showMessageDialog(null, "no task");
                }
                window.fireChanges();
	}
	
}
